package mi.payment.transaction.sale;

import android.annotation.SuppressLint;

import mi.payment.R;
import mi.payment.bean.db.TradeData;
import mi.payment.constants.Params;
import mi.payment.controller.BaseController;
import mi.payment.db.dao.PayDetail;
import mi.payment.ui.base.PageRoute;
import mi.payment.ui.base.ParentActivity;
import mi.payment.utils.transaction.PayResultQueryTask;
import sunmi.payment.L3.L3Params;
import sunmi.payment.ui.dialog.LoadDialog;

/**
 * 自定义订单结果查询（科脉订单查询）
 */
public class PayOrderResultQueryController extends BaseController {

    public PayOrderResultQueryController(ParentActivity activity) {
        super(activity);
    }

    public void queryQRCodeResult() {
        L3Params l3Params = Params.sL3Params;
        TradeData tradeData = Params.newTradeData();
        PayDetail reqPayDetail = tradeData.getPayDetail();
        reqPayDetail.TradeDate = l3Params.oriTransDate;
        reqPayDetail.customOrderNo = l3Params.transId;
        int type = l3Params.paymentType;
        if (type == 1 || type == 2) {
            reqPayDetail.transPlatform = 1;
        } else if (type == 3 || type == 4) {
            reqPayDetail.transPlatform = 2;
        } else {
            reqPayDetail.transPlatform = 0;
        }

        @SuppressLint("StaticFieldLeak")
        PayResultQueryTask task = new PayResultQueryTask(activity) {

            @Override
            protected void onPostExecuteImpl(TradeData tradeData) {
                PayDetail resPay = tradeData.getPayDetail();
                PageRoute.startAction(mActivity, PageRoute.TYPE_ORDER_QUERY, resPay);
            }

            @Override
            protected void onTaskTimeoutImpl() {
                PageRoute.startTimeoutAction(mActivity, PageRoute.TYPE_ORDER_QUERY, reqPayDetail);
            }

        };
        LoadDialog loadingDialog = activity.getLoadingDialog(R.string.load_search);
        task.setLoadDialog(loadingDialog);
        task.execute(tradeData);
    }


}
